package com.corpgovernment.common.supplier;

import com.google.common.hash.HashCode;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;

import java.nio.charset.Charset;

public final class MD5Util {
    private static Charset DEFAULT_CHARSET = Charset.forName("UTF-8");

    public MD5Util() {
    }

    public static String md5(String source) {
        String ciphertext = "";
        if (null == source) {
            return ciphertext;
        } else {
            HashFunction hf = Hashing.md5();
            HashCode hash = hf.newHasher().putString(source, DEFAULT_CHARSET).hash();
            ciphertext = hash.toString();
            return ciphertext;
        }
    }
}